package com.substation.ui.fragment;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bean.HomeItem;
import com.bumptech.glide.Glide;
import com.jessewu.library.SuperAdapter;
import com.jessewu.library.view.ViewHolder;
import com.substation.R;
import com.substation.ui.utils.BannerUtils;
import com.substation.ui.weight.DividerGridItemDecoration;
import com.substation.utils.ScreenUtils;
import com.wenld.wenldbanner.WenldBanner;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by admin on 2018/5/15.
 */

public class HomeFragment extends BaseFragment {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.commonBanner)
    WenldBanner commonBanner;
    @BindView(R.id.list)
    RecyclerView list;
    List<String> bannerList=new ArrayList<>();

    List<HomeItem> datas=new ArrayList<>();
    SuperAdapter<HomeItem> adapter;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_home;
    }

    @Override
    protected void initView() {
        toolbar.setTitle("首页");
        LinearLayout.LayoutParams layoutParams=new LinearLayout.LayoutParams(ScreenUtils.getScreenWidth(context),ScreenUtils.getScreenWidth(context)/2);
        commonBanner.setLayoutParams(layoutParams);
        bannerList.add("http://img.zcool.cn/community/016e94571388ac32f8758c9b05b4bb.jpg@2o.jpg");
        bannerList.add("http://www.ferro-alloys.com/UploadFiles/image/news/News1/2015.10/110KVA%E5%8F%98%E7%94%B5%E7%AB%99.png");
        bannerList.add("http://img60.ybzhan.cn/9/20170601/636319326135126184893.jpg");
        bannerList.add("http://img66.chem17.com/9/20150827/635762839967094062570.png");
        BannerUtils.setBannerString(context,bannerList,commonBanner);

        list.setLayoutManager(new GridLayoutManager(context,3));
        list.addItemDecoration(new DividerGridItemDecoration(context));
        datas.addAll(HomeItem.getHomeItem(context));
        list.setAdapter(adapter=new SuperAdapter<HomeItem>(R.layout.content_fragment_home) {
            @Override
            public void bindView(ViewHolder viewHolder, HomeItem homeItem, int i) {
                Glide.with(context).load(homeItem.getImgRes()).into((ImageView) viewHolder.getView(R.id.image_top));
                ((TextView)viewHolder.getView(R.id.text)).setText(homeItem.getTitle());
                viewHolder.getView(R.id.layout).setOnClickListener(homeItem.getListener());
            }
        });
        adapter.setData(datas);
    }

}
